package Huihu.src.IO;

import java.io.*;

public class Kbwj1 {
    public static void main(String[] args) throws IOException {
        //需求：通过字符流拷贝文件，一次读写一个字符
        //例如，将1.txt的内容复制到2.txt上面
        //创建字符输入、输出流对象
        Reader reader=new FileReader("Libs/1.txt");
        Writer writer=new FileWriter("libs/2.txt");
        char [] chs=new char[1024];
        StringBuilder sb=new StringBuilder();
        int ch;
        //输入流读取1.txt里面的内容
        for (int i = 0; i < chs.length; i++) {
            if ((ch = reader.read()) != -1) {
                chs[i] = (char) ch;
                sb.append(chs[i]);
            }
        }
        /*
        第二种方法：
        while ((ch = reader.read(chs)) != -1) {
            writer.write(chs,0,ch);
        }
         */
        String str=sb.toString();
        writer.write(str.trim());
        reader.close();
        writer.close();

        /*
        网上老师的方法
        FileReader fr=new FileReader("Libs/1.txt");
        FileWriter fw=new FileWriter("Libs/2.txt");
        int len;
        while ((len = fr.read()) != -1) {
            fw.write(len);
        }
        fr.close();
        fw.close();
         */
    }
}
